//
//  HNSH_CreateChatGroupTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_CreateChatGroupTopView.h"

@interface HNSH_CreateChatGroupTopView ()
/* bgView */
@property (nonatomic, strong) UIView *grayBgView;
/* searchImgView */
@property (nonatomic, strong) UIImageView *searchImgView;
/** */
@property (nonatomic, strong)UITextField * textField;
@end

@implementation HNSH_CreateChatGroupTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor appWhiteLabelColor];
    [self addSubview:self.grayBgView];
    [self.grayBgView addSubview:self.searchImgView];
    [self.grayBgView addSubview:self.textField];
    
}

- (void)addAllLayout{
    [self.grayBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(36);
        make.top.mas_equalTo(8);
    }];
    [self.searchImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.width.height.mas_equalTo(20);
        make.centerY.mas_equalTo(self.grayBgView);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.searchImgView.mas_right).offset(8);
        make.top.height.right.mas_equalTo(self.grayBgView);
    }];
}

//MARK: Setter Methods
- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [UITextField new];
        _textField.font = [UIFont systemFontOfSize:12];
        _textField.textColor = [UIColor appBlack333LabelColor];
        _textField.placeholder = @"搜索";
        [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _textField;
}

- (UIView *)grayBgView{
    if (!_grayBgView) {
        _grayBgView = [UIView new];
        _grayBgView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
        _grayBgView.layer.cornerRadius = 18;
        _grayBgView.layer.masksToBounds = YES;
    }
    return _grayBgView;
}

- (UIImageView *)searchImgView{
    if (!_searchImgView) {
        _searchImgView = [UIImageView new];
        _searchImgView.image = [UIImage imageNamed:@"base_nav_search"];
    }
    return _searchImgView;
}

//MARK: UITextViewDelegate Methods
- (void)textFieldDidChange:(UITextField *)textField{
    if (self.searchBlock) {
        self.searchBlock(textField.text);
    }
}


@end
